package files;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;

public class MmapFile {
    public static void main(String[] args) {
        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 1; i++) {
                    Path path = FileSystems.getDefault().getPath("/home/java","aaa.txt" );
                    try {
                        System.out.println("1111");
                        FileChannel fileChannel = FileChannel.open(path, StandardOpenOption.READ,StandardOpenOption.WRITE);
                        System.out.println("2222");
                        MappedByteBuffer byteBuffer = fileChannel.map(FileChannel.MapMode.READ_WRITE, 0, 40960);
                        System.out.println("3333");
                        byte[] bytes = new byte[4096];
                        byteBuffer.get(bytes);
                        System.out.println("4444");
                        String str = new String(bytes);
                        System.out.println(str);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }

            }
        });
        thread.start();

    }
}
